package hellohandler

import (
	"context"
	//"hmsDemo/hms.service/taskflow"

	//validation "github.com/go-ozzo/ozzo-validation/v4"

	config "hmsDemo/hms.service/config"
	//"github.com/micro/go-micro/v2/util/log"
	hello "hmsDemo/common/proto/helloworld"
	"hmsDemo/hms.service/handler"

	log "gitee.com/tgodfather/misc/logger"
	"go.uber.org/zap"
)

var (
//ErrParamInvalid = errors.New("Input Param invalid")
)

func init() {
	handler.RegisterHandlerPlugin("handler.hello", helloHandlerInit)
}

func helloHandlerInit(hc *handler.HandlerCenter) error {
	helloH := newhelloHandler(hc)
	err := hello.RegisterGreeterHandler(hc.GetServer(), helloH)
	if nil != err {
		log.Error("hello.RegisterhelloServiceHandler", zap.Error(err))
	} else {
		log.Info("hello.RegisterhelloServiceHandler")
	}
	return err
}

type helloHandler struct {
	//Config *config.ServiceConfig
	cfg *config.ServiceConfig
	// flow string //工作流名字, 每个接口都需要一个配置，通过params进行设置
	//tf               *taskflow.TaskFactory
	flowNameCrawM3u8 string
}

func newhelloHandler(hc *handler.HandlerCenter) *helloHandler {
	hms := new(helloHandler)
	//hms.cfg = cfg
	//hms.tf = hc.GetTaskFactory()
	hms.flowNameCrawM3u8 = "helloM3u8"

	if paramValue, ok := hc.GetParam("hms.Handler.helloM3u8.FlowName"); ok {
		hms.flowNameCrawM3u8 = paramValue
	}
	log.Info("helloHandler Init param ",
		zap.String("hms.ImageHandler.ImageAnalysis.flowName", hms.flowNameCrawM3u8))

	return hms
}

func (e *helloHandler) SayHello(ctx context.Context, in *hello.HelloRequest, out *hello.HelloReply) error {
	//检查参数
	log.Info("Recv Req SayHello", zap.Reflect("req", in))

	//根据请求类型 进行处理
	// flowName := e.flowNameCrawM3u8
	out.Message = "Hello " + in.GetName()
	return nil
}
